package com.enmo.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.enmo.service.TreeService;

@Controller
public class TreeAction extends BaseAction{
	private static final long serialVersionUID = 1L;
	
	private TreeService treeService;
	
	@Action(
			value = "treejson",
			results = {
				@Result(name = "success" , location = "tree.jsp" , type = "dispatcher")
			}
	)
	public String getTree(){
		List<String> list = getTreeService().getTree();
		//System.out.println(list);
        ServletActionContext.getResponse().setContentType(
				"text/html; charset=UTF-8");
        PrintWriter printWriter = null;
		try {
			printWriter = ServletActionContext.getResponse().getWriter();
			printWriter.write(list.toString());// 往前台写入数据流
		} catch (IOException e) {
			System.out.println("往前台页面写入数据时IO异常!");
		} finally {
			printWriter.close();
		}
        
		return SUCCESS;
	}
	@Action(
			value = "treejson2"
			/*results = {
			@Result(name = "success" , location = "tree.jsp" , type = "dispatcher")
		}*/
	)
	public void cc(){
		ServletActionContext.getResponse().setContentType(
				"text/html; charset=UTF-8");
        PrintWriter printWriter = null;
		try {
			printWriter = ServletActionContext.getResponse().getWriter();
			printWriter.write("json2222222");// 往前台写入数据流
			//System.out.println("json2");
		} catch (IOException e) {
			System.out.println("往前台页面写入数据时IO异常!");
		} finally {
			printWriter.close();
		}
		//return SUCCESS;
	}
	//get set 
	public TreeService getTreeService() {
		return treeService;
	}
	@Autowired
	public void setTreeService(TreeService treeService) {
		this.treeService = treeService;
	}
}
